<%-- 
    Document   : manage-user-action
    Created on : Feb 13, 2012, 4:41:56 PM
    Author     : lab
--%>
<%@page import="util.PagingUtil"%>
<%@page import="util.SharingUtil"%>
<%@page import="dto.User"%>
<%@page import="java.util.ArrayList"%>
<%@page import="dao.UserDAO"%>
<%
    UserDAO daoUser = new UserDAO();
    int currentPage = PagingUtil.getPageNumber(request.getParameter("page"));
    ArrayList<User> list = new ArrayList<User>();
    list = daoUser.getUsers(currentPage, PagingUtil.CONST_PAGE_SIZE);
    request.setAttribute("list", list);
    int totalRecords = daoUser.getTotalRecords();
    int pageSize = PagingUtil.CONST_PAGE_SIZE;
    String pagingBar = PagingUtil.getPageNavigator(totalRecords, pageSize, currentPage, "?pcontent=manage-user&page=");
    if (request.getParameter("delete") != null) {
        int id = Integer.parseInt(request.getParameter("id"));
        if (daoUser.delete(id) > 0) {
            session.setAttribute(SharingUtil.VAR_S_ADMIN_MESSAGE, "User account is removed");
        } else {
            session.setAttribute(SharingUtil.VAR_S_ADMIN_MESSAGE, "Error occured. User account cannot be removed");
        }
    }
%>